package com.hinacom.pix.receiver;

import ca.uhn.hl7v2.app.SimpleServer;
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

import org.apache.log4j.Logger;


/**
 * Created by fyu on 2016/11/25.
 */
public class NotificationReceiver extends SimpleServer {
    private static Logger logger = Logger.getLogger(NotificationReceiver.class);
    public NotificationReceiver(int port) {
        super(port);
    }

    public static void main(String[] args) {
        // 记录debug级别的信息
        logger.debug("Notification start ...");
        Properties properties = new Properties();

        try {
            String configFile = args[0];
            InputStream inputStream = new FileInputStream(configFile);
            properties.load(inputStream);
            inputStream.close();
        } catch (Exception e) {
            logger.error("Start error:" + e);
        }finally {

        }

        String notificationPort =  properties.getProperty("notification-port");
        int port = Integer.valueOf(notificationPort);
        NotificationReceiver receiver = new NotificationReceiver(port);
        PIXComsumerHandler handler = new PIXComsumerHandler(properties);
        receiver.registerApplication("ADT", "A31", handler);

        logger.info("Notification ready ...");
        receiver.start();
    }
}
